package com.kabao.demo;


import jakarta.servlet.FilterChain;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.web.filter.OncePerRequestFilter;

import java.io.IOException;

/**
 * 请求包装过滤器：将原始请求包装为ContentCachingRequestWrapper
 * 确保请求体可被多次读取（拦截器、控制器等均可读取）
 */
public class RequestWrapperFilter extends OncePerRequestFilter {

    @Override
    protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response,
                                    FilterChain filterChain) throws ServletException, IOException {
        RequestWrapper requestWrapper = new RequestWrapper(request);
//        String bodyString = requestWrapper.getBodyString();
//        System.out.println("bodyString = " + bodyString);
        filterChain.doFilter(requestWrapper, response);
    }
}

